package com.example.arithmeticleetcode.leetcode.July;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-07-11 11:54
 **/
public class Demo06 {

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 1, 1, 3};
        System.out.println(numIdenticalPairs(nums)); // 4

        int[] nums1 = {1, 1, 1, 1};
        System.out.println(numIdenticalPairs(nums1)); //6

        int[] nums2 = {1, 2, 3};
        System.out.println(numIdenticalPairs(nums2)); //0
    }

    public static int numIdenticalPairs(int[] nums) {
        int count = 0;
        int sum = nums.length;
        for (int i = 0, len = sum - 1; i < len; i++) {
            for (int j = i + 1, len2 = sum; j < len2; j++) {
                if (nums[i] == nums[j]) {
                    count++;
                }
            }
        }
        return count;
    }
}
